1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module adw.Avatar;
26 
27 private import adw.c.functions;
28 public  import adw.c.types;
29 private import gdk.PaintableIF;
30 private import gdk.Texture;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import glib.c.functions;
34 private import gobject.ObjectG;
35 private import gtk.AccessibleIF;
36 private import gtk.AccessibleT;
37 private import gtk.BuildableIF;
38 private import gtk.BuildableT;
39 private import gtk.ConstraintTargetIF;
40 private import gtk.ConstraintTargetT;
41 private import gtk.Widget;
42 
43 
44 /**
45  * A widget displaying an image, with a generated fallback.
46  * 
47  * <picture>
48  * <source srcset="avatar-dark.png" media="(prefers-color-scheme: dark)">
49  * <img src="avatar.png" alt="avatar">
50  * </picture>
51  * 
52  * `AdwAvatar` is a widget that shows a round avatar.
53  * 
54  * `AdwAvatar` generates an avatar with the initials of  the
55  * [property@Avatar:text] on top of a colored background.
56  * 
57  * The color is picked based on the hash of the [property@Avatar:text].
58  * 
59  * If [property@Avatar:show-initials] is set to `FALSE`,
60  * [property@Avatar:icon-name] or `avatar-default-symbolic` is shown instead of
61  * the initials.
62  * 
63  * Use [property@Avatar:custom-image] to set a custom image.
64  * 
65  * ## CSS nodes
66  * 
67  * `AdwAvatar` has a single CSS node with name `avatar`.
68  *
69  * Since: 1.0
70  */
71 public class Avatar : Widget
72 {
73 	/** the main Gtk struct */
74 	protected AdwAvatar* adwAvatar;
75 
76 	/** Get the main Gtk struct */
77 	public AdwAvatar* getAvatarStruct(bool transferOwnership = false)
78 	{
79 		if (transferOwnership)
80 			ownedRef = false;
81 		return adwAvatar;
82 	}
83 
84 	/** the main Gtk struct as a void* */
85 	protected override void* getStruct()
86 	{
87 		return cast(void*)adwAvatar;
88 	}
89 
90 	/**
91 	 * Sets our main struct and passes it to the parent class.
92 	 */
93 	public this (AdwAvatar* adwAvatar, bool ownedRef = false)
94 	{
95 		this.adwAvatar = adwAvatar;
96 		super(cast(GtkWidget*)adwAvatar, ownedRef);
97 	}
98 
99 
100 	/** */
101 	public static GType getType()
102 	{
103 		return adw_avatar_get_type();
104 	}
105 
106 	/**
107 	 * Creates a new `AdwAvatar`.
108 	 *
109 	 * Params:
110 	 *     size = The size of the avatar
111 	 *     text = the text used to get the initials and color
112 	 *     showInitials = whether to use initials instead of an icon as fallback
113 	 *
114 	 * Returns: the newly created `AdwAvatar`
115 	 *
116 	 * Since: 1.0
117 	 *
118 	 * Throws: ConstructionException GTK+ fails to create the object.
119 	 */
120 	public this(int size, string text, bool showInitials)
121 	{
122 		auto __p = adw_avatar_new(size, Str.toStringz(text), showInitials);
123 
124 		if(__p is null)
125 		{
126 			throw new ConstructionException("null returned by new");
127 		}
128 
129 		this(cast(AdwAvatar*) __p);
130 	}
131 
132 	/**
133 	 * Renders @self into a [class@Gdk.Texture] at @scale_factor.
134 	 *
135 	 * This can be used to export the fallback avatar.
136 	 *
137 	 * Params:
138 	 *     scaleFactor = The scale factor
139 	 *
140 	 * Returns: the texture
141 	 *
142 	 * Since: 1.0
143 	 */
144 	public Texture drawToTexture(int scaleFactor)
145 	{
146 		auto __p = adw_avatar_draw_to_texture(adwAvatar, scaleFactor);
147 
148 		if(__p is null)
149 		{
150 			return null;
151 		}
152 
153 		return ObjectG.getDObject!(Texture)(cast(GdkTexture*) __p, true);
154 	}
155 
156 	/**
157 	 * Gets the custom image paintable.
158 	 *
159 	 * Returns: the custom image
160 	 *
161 	 * Since: 1.0
162 	 */
163 	public PaintableIF getCustomImage()
164 	{
165 		auto __p = adw_avatar_get_custom_image(adwAvatar);
166 
167 		if(__p is null)
168 		{
169 			return null;
170 		}
171 
172 		return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p);
173 	}
174 
175 	/**
176 	 * Gets the name of an icon to use as a fallback.
177 	 *
178 	 * Returns: the icon name
179 	 *
180 	 * Since: 1.0
181 	 */
182 	public string getIconName()
183 	{
184 		return Str.toString(adw_avatar_get_icon_name(adwAvatar));
185 	}
186 
187 	/**
188 	 * Gets whether initials are used instead of an icon on the fallback avatar.
189 	 *
190 	 * Returns: whether initials are used instead of an icon as fallback
191 	 *
192 	 * Since: 1.0
193 	 */
194 	public bool getShowInitials()
195 	{
196 		return adw_avatar_get_show_initials(adwAvatar) != 0;
197 	}
198 
199 	/**
200 	 * Gets the size of the avatar.
201 	 *
202 	 * Returns: the size of the avatar
203 	 *
204 	 * Since: 1.0
205 	 */
206 	public int getSize()
207 	{
208 		return adw_avatar_get_size(adwAvatar);
209 	}
210 
211 	/**
212 	 * Gets the text used to generate the fallback initials and color.
213 	 *
214 	 * Returns: the text used to generate the fallback initials and
215 	 *     color
216 	 *
217 	 * Since: 1.0
218 	 */
219 	public string getText()
220 	{
221 		return Str.toString(adw_avatar_get_text(adwAvatar));
222 	}
223 
224 	/**
225 	 * Sets the custom image paintable.
226 	 *
227 	 * Params:
228 	 *     customImage = a custom image
229 	 *
230 	 * Since: 1.0
231 	 */
232 	public void setCustomImage(PaintableIF customImage)
233 	{
234 		adw_avatar_set_custom_image(adwAvatar, (customImage is null) ? null : customImage.getPaintableStruct());
235 	}
236 
237 	/**
238 	 * Sets the name of an icon to use as a fallback.
239 	 *
240 	 * If no name is set, `avatar-default-symbolic` will be used.
241 	 *
242 	 * Params:
243 	 *     iconName = the icon name
244 	 *
245 	 * Since: 1.0
246 	 */
247 	public void setIconName(string iconName)
248 	{
249 		adw_avatar_set_icon_name(adwAvatar, Str.toStringz(iconName));
250 	}
251 
252 	/**
253 	 * Sets whether to use initials instead of an icon on the fallback avatar.
254 	 *
255 	 * Params:
256 	 *     showInitials = whether to use initials instead of an icon as fallback
257 	 *
258 	 * Since: 1.0
259 	 */
260 	public void setShowInitials(bool showInitials)
261 	{
262 		adw_avatar_set_show_initials(adwAvatar, showInitials);
263 	}
264 
265 	/**
266 	 * Sets the size of the avatar.
267 	 *
268 	 * Params:
269 	 *     size = The size of the avatar
270 	 *
271 	 * Since: 1.0
272 	 */
273 	public void setSize(int size)
274 	{
275 		adw_avatar_set_size(adwAvatar, size);
276 	}
277 
278 	/**
279 	 * Sets the text used to generate the fallback initials and color.
280 	 *
281 	 * Params:
282 	 *     text = the text used to get the initials and color
283 	 *
284 	 * Since: 1.0
285 	 */
286 	public void setText(string text)
287 	{
288 		adw_avatar_set_text(adwAvatar, Str.toStringz(text));
289 	}
290 }